package p1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-06-07
 * Time: 14:23
 */
public class demo6 {
    //Thread构造方法
    public static void main1(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            while (true) {
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "myThread");//给线程取名字
        //Thread(Runnable target,String name)
        t.start();

        while (true) {
            System.out.println("hello main");
            Thread.sleep(1000);
        }
    }

    //Thread类的属性:1.ID身份标识,getId()
    //Thread类的属性:2.名字,线程的名字,getName()
    //Thread类的属性:3.状态,getState()
    //Thread类的属性:4.优先级,getPriority()
    public static void main(String[] args) {
        Thread t = new Thread(() -> {
            while (true) {
                System.out.println("Hello Thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"自定义线程名字");
        t.start();

        //获取属性
        System.out.println("线程ID: " + t.getId());
        System.out.println("线程名字: " + t.getName());
        System.out.println("线程状态: " + t.getState());
        System.out.println("线程优先级: " + t.getPriority());

    }
}
